\documentclass[12pt]{article}
\usepackage{amsmath,amsthm}
\usepackage{times}
\usepackage{verbatim}

\newtheorem{defn}{Definition}
\newtheorem{lem}{Lemma}
\newtheorem{thm}{Theorem}

\begin{document}

\section*{Administrivia}
\paragraph{}
\begin{itemize}
\item Assignment 1 is to be done individually.
\item You should have a basic polling loop somewhere in your A1 code by now.
\end{itemize}

\section*{Polling Loops, continued}
\paragraph{}
The serial ports on the EP-9302 communicate at 115 kbps, or approximately
15k characters per second. Your program must be capable of reading all input
characters, so that the polling loop must execute in less than 60-80
\mu s. However, it is very unlikely that your polling loop will execute
within this time limit. To work around this, you can check for input multiple
times:

\begin{verbatim}
FOREVER {
  if (c1) a1;
  if (c2) a2;
  if (c1) a1;
}
\end{verbatim}

If even this is not enough, we could split up \verb=c2=:

\begin{verbatim}
FOREVER {
  if (c1) a1;
  if (c2.1) a2.1;
  if (c1) a1;
  if (c2.2) a2.2;
}
\end{verbatim}

\section*{Other Ways}
\paragraph{}
You may notice that the polling loop spends the vast majority of its time,
well, polling - it repeatedly checks conditions that are almost always false.
It would be nice to have a way of simply waking up appropriate sections of
code ``on demand'', i.e. in response to interrupts. These sections of code
act as listeners for these interrupt events.

\paragraph{}
Interrupt Service Routines allow you to do just this; you insert pieces of
code (actually, function pointers to functions containing said code) into a
jump table. This can be done in C.

\section*{Communicating With The Marklin Train}
\paragraph{}
\begin{itemize}
\item Set up the UART so that it speaks with the train properly.
  \begin{itemize}
  \item 2400 bps serial communication over COM1
  \item appropriate stop bits, control register values, etc.
  \end{itemize}
\end{itemize}

\paragraph{}
The train controller operates in a high-noise environment, and must operate
slowly in order to deal with the current/voltage spikes created by this noise.
However, it is connected to the serial port of a comparatively much faster
device, which is fully capable of overflowing the train controller buffer.
If the buffer overflows, the train controller will most likely crash.

\paragraph{}
To this effect, the train controller can instruct the EP-9302 (via the
RS-232 protocol) that its buffers are overflowing. In this event:

\begin{itemize}
\item The train controller transmits \verb=XOFF= (ctrl-s) to the UART.
\item The UART passes \verb=XOFF= to the CPU.
\end{itemize}

This effectively stops communication. To start it again, the process is
repeated with \verb=XON= (ctrl-q).

\end{document}
